﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A90合并数组并排序
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 3, 5, 7, 2, 1 };
            int[] arr1 = { 9, 12, 4 };

            //创建新数组
            int[] arr2 = new int[arr.Length + arr1.Length];
            //把元素放到新数组
            for (int i = 0; i < arr2.Length; i++)
            {
                arr2[i] = i < arr.Length ? arr[i] : arr1[i - arr.Length];
                // if (i<arr.Length)
                // {
                //     arr2[i] = arr[i];
                // }
                // els
                // {
                //     arr2[i] = arr1[i - arr.Length];
                // }
            }

            //排序
            Sort(arr2);
        }

        private static void Sort(int[] arr2)
        {
            for (int i = 0; i < arr2.Length - 1; i++)
            {
                for (int j = 0; j < arr2.Length - 1 - i; j++)
                {
                    if (arr2[j] > arr2[j + 1])
                    {
                        int temp = arr2[j];
                        arr2[j] = arr2[j + 1];
                        arr2[j + 1] = temp;
                    }
                }
            }
            foreach (var item in arr2)
            {
                Console.WriteLine(item);
            }
        }

    }
}
